package test1;

import java.util.Random;
import java.util.concurrent.TimeUnit;

public class Phone {
     public synchronized void call(){
        System.out.println("开始打电话");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("结束打电话");
    }

    public synchronized void msg(){
        System.out.println("开始发短信");
        try {
            TimeUnit.SECONDS.sleep(new Random().nextInt(3));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("结束发短信");
    }
}
